/*
 * ACLEvent.java
 *
 * Created on September 3, 2006, 12:12 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.blackwatchplaid;
import java.util.Date;
import org.json.*;

/**
 * An ACL event is a unique id, a name, a start and finish time, and a stage.
 * E.g. "1025", "Gnarls Barkley", "AT&T", Friday 4:30PM Central - 5:30PM
 */
public class ACLEvent {
    String _id;
    String _name;
    Date _start;
    Date _finish;
    String _stage;

    // At one point I screwed up the dates when I wrote out the schedule .json
    // because they are in there as UTC time. This can be used to brings time back 
    // to CST (-6) or CDT (-5), but it is no longer needed.
    final static long kCentralGMTOffestMillis = 0;//5L*60*60*1000;
    
    /** Creates a new instance of ACLEvent */
    public ACLEvent(JSONObject j) {
        this(j.getString("id"), j.getString("name"), new Date(kCentralGMTOffestMillis+(long)j.getDouble("start")), new Date(kCentralGMTOffestMillis+(long)j.getDouble("finish")), j.getString("stage"));
    }
    
    public ACLEvent(String id, String name, Date start, Date finish, String stage) {
        _id = id;
        _name = name;
        _start = start;
        _finish = finish;
        _stage = stage;
    }
    public String id() {
        return _id;
    }
    public String name() { return _name; }
    public Date start() { return _start; }
    public Date finish() { return _finish; }
    public String stage() { return _stage; }
    public String toString() { return _id+"_"+_name+"_"+_start+"-"+_finish+"_"+_stage; }
    public JSONObject toJSON() { 
        JSONObject j = new JSONObject();
        j.put("id",id());
        j.put("start",start().getTime());
        j.put("finish",finish().getTime());
        j.put("stage",stage());
        j.put("name",name());
        return j;
    }
}
